﻿
@{
    News news = ViewBag.news;
    ViewBag.Title = news.title;
    Layout = "~/Views/Shared/_layout.cshtml";
}
@section sidebar {
    @Html.Partial("_detail_sidebar")
}
<article>
    <h3 class="news-detail-title">@news.title</h3>
    <div class="row">
        <div class="col-md-2">发布人：</div>
        <div class="col-md-4">@UserView.GetUserById((int) news.publisher).name</div>
        <div class="col-md-2">发布时间：</div>
        <div class="col-md-4">@news.date</div>
    </div>
    <br />
    @news.content
</article>
@{
    User user = (User)Session["user"];
    if (user != null && user.rank == (int) UserRank.ADMINISTATOR)
    {
        <div class="modal fade bs-example-modal-sm es-delete-dialog" role="dialog" tabindex="-1" aria-labelledby="删除" style="display: none;">
            <div class="modal-dialog modal-sm" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                        <h4 class="modal-title">删除新闻,此操作不可撤销</h4>
                    </div>
                    <div class="modal-body">
                        <a class="btn btn-lg btn-danger btn-block" id="newsdelete" href="#">删除</a>
                    </div>
                </div>
            </div>
        </div>
        <script>
            $('#newsdelete').click(function (event) {
                $.ajax({
                    type: "POST",
                    url: "/News/Delete",
                    data: "id=@news.nid",
                    success: function (data) {
                        if (data === true) {
                            window.location.href = "/News/Index";
                        } else {
                            alert("删除新闻失败");
                        }
                    }
                })
            });
        </script>
    }
}
